<template>
<view class="identification-box">
  <view class="cu-list menu">
    <view class="cu-item arrow border-top" @tap="onTapCell('isauth')">
      <view class="content">实名认证</view>
      <view class="action" :class="isauth ? '' : 'text-orange'">{{isauth ? '已' : '未'}}认证</view>
    </view>
    <view class="cu-item arrow" @tap="onTapCell('isinfo')">
      <view class="content">基本信息</view>
      <view class="action" :class="isinfo ? '' : 'text-orange'">{{isinfo ? '已' : '未'}}认证</view>
    </view>
    <view class="cu-item arrow" @tap="onTapCell('isaddrbook')">
      <view class="content">通讯录认证</view>
      <view class="action" :class="isaddrbook ? '' : 'text-orange'">{{isaddrbook ? '已' : '未'}}认证</view>
    </view>
    <!-- <view class="cu-item arrow" @tap="onTapCell">
      <view class="content">绑定银行卡</view>
      <view class="action" :class="istiebank ? '' : 'text-orange'">{{istiebank ? '已' : '未'}}认证</view>
    </view> -->
    <!-- <view class="cu-item arrow" @tap="onTapCell">
      <view class="content">运营商认证</view>
      <view class="action" :class="ismobile ? '' : 'text-orange'">{{ismobile ? '已' : '未'}}认证</view>
    </view> -->
  </view>
  <view class="padding text-gray text-right">
    <text class="cuIcon-info"></text>请按顺序完成以上认证
  </view>
</view>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'identification', // 资料认证
  data () {
    return {
    }
  },
  computed: {
    ...mapGetters([
      'userBasicInfo'
    ]),
    /** 是否实名认证 */
    isauth() {
      return this.userBasicInfo.isauth == 1
    },
    /** 是否基本信息认证 */
    isinfo() {
      return this.userBasicInfo.isinfo == 1
    },
    /** 是否上传通讯录 */
    isaddrbook() {
      return this.userBasicInfo.isaddrbook == 1
    },
    /** 是否绑定银行卡 */
    istiebank() {
      return this.userBasicInfo.istiebank == 1
    },
    /** 是否运营商认证 */
    ismobile() {
      return this.userBasicInfo.ismobile == 1
    },
    /** 是否可以进行通讯录认证 */
    cannotGoAddress() {
      return !this.isauth || !this.isinfo
    },
    /** 是否可以进入基本信息认证 */
    cannotGoBasicInfo() {
      return !this.isauth
    }
  },
  onShow() {
    this.init()
  },
  methods: {
    init() {
      this.getUserBasicInfo()
    },
    /** 获取用户基本信息 */
    getUserBasicInfo() {
      return new Promise(resolve => {
        this.$api.getUserBasicInfo().then(res => {
          console.log('用户基本信息', res)
          if (!res) return
          const resData = res.data
          this.$store.commit('SET_USER_BASIC_INFO', resData)
          resolve()
        })
      })
    },
    async onTapCell(key) {
      switch (key) {
        case 'isaddrbook':
          if (this.isaddrbook) return
          if (this.cannotGoAddress) {
            this.$showTipsToast('请按顺序完成以上认证')
            return
          }
          await this.$store.dispatch('saveUserAddressBook')
          this.$showSuccessToast('认证成功')
          this.init()
          break
        case 'isinfo':
          if (this.cannotGoBasicInfo) {
            this.$showTipsToast('请按顺序完成以上认证')
            return
          }
          this.$Router.push({ name: 'basic-information' })
          break;
        case 'isauth':
          if (this.isauth) return
          this.$Router.push({ name: 'authentication' })
          break;
      }
    }
  }
}
</script>

<style lang="less">
</style>
